package com.sh.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sh.common.ResponseInfoEnum;
import com.sh.common.ReturnVO;
import com.sh.entity.SystemParam;
import com.sh.entity.User;
import com.sh.exception.CustomException;
import com.sh.service.SystemService;
import com.sh.util.ConstantUtil;
import com.sh.util.DataUtil;
import com.sh.util.DateUtil;

/**
 *  系统 相关 controller
 * */
@RestController
@RequestMapping("/api/system")
public class SystemController extends BaseController{
	@Autowired
	SystemService systemService;


	@ResponseBody
	@RequestMapping("/listMenus")
	public ReturnVO listMenus(){

		User user = null;
		SystemParam rootNode = null;
		try {

			String sysTime = DateUtil.getSysTime("yyyy-MM-dd hh:mm:ss");
			Map<String,Object> conMap = new HashMap<String,Object>();
			conMap.put("type",ConstantUtil.SYSTEM_PARAM_MENU);
			conMap.put("name", "");

			List<SystemParam> list =
					systemService.listMenus(conMap,user,sysTime);

			rootNode = DataUtil.getTreeJsonObj(list);

		} catch (Exception e) {
			// TODO Auto-generated catch block
			log.error("菜单项目查询异常:",e);
			return failForService("400", ResponseInfoEnum.SYSTEM_PARAM_SUCCESS,e.getMessage());

		}
		return succForService(ResponseInfoEnum.SYSTEM_PARAM_SUCCESS, rootNode);

	}
}
